﻿/*
Ngày 2014-04-25:
Cập nhật cascade delete dùng trong xóa File
*/
--================================
--Thêm cascade delete tblFile sẽ delete tblFileExchange
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_tblFileExchange_tblFile]') AND parent_object_id = OBJECT_ID(N'[dbo].[tblFileExchange]'))
ALTER TABLE [dbo].[tblFileExchange] DROP CONSTRAINT [FK_tblFileExchange_tblFile]
GO
ALTER TABLE [dbo].[tblFileExchange]  WITH CHECK ADD  CONSTRAINT [FK_tblFileExchange_tblFile] FOREIGN KEY([ID_File])
REFERENCES [dbo].[tblFile] ([ID_File])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[tblFileExchange] CHECK CONSTRAINT [FK_tblFileExchange_tblFile]
go
--================================
--Thêm cascade delete tblHBL sẽ delete tblHBLExchange
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_tblHBLExchange_tblHBL]') AND parent_object_id = OBJECT_ID(N'[dbo].[tblHBLExchange]'))
ALTER TABLE [dbo].[tblHBLExchange] DROP CONSTRAINT [FK_tblHBLExchange_tblHBL]
GO
ALTER TABLE [dbo].[tblHBLExchange]  WITH CHECK ADD  CONSTRAINT [FK_tblHBLExchange_tblHBL] FOREIGN KEY([ID_HBL])
REFERENCES [dbo].[tblHBL] ([ID_HBL])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[tblHBLExchange] CHECK CONSTRAINT [FK_tblHBLExchange_tblHBL]
